<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/public/head::head(~{::title},~{},~{})">
    <title>管理员修改-新闻管理系统</title>
</head>

<body>
<style>
    .weadmin-body {
        padding: 20px;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
</style>
<div class="weadmin-body">
    <form class="layui-form layui-form-pane" id="form">
        <input type="hidden" name="id" th:value="${session.user.id}" />
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="we-red">*</span>姓名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" th:value="${session.user.name}" required lay-verify="required"
                       placeholder="姓名" autocomplete="off"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="mobile" class="layui-form-label">
                <span class="we-red">*</span>手机号
            </label>
            <div class="layui-input-inline">
                <input type="text" id="mobile" name="mobile" th:value="${session.user.mobile}" required lay-verify="required"
                       placeholder="手机号" autocomplete="off"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="code" class="layui-form-label">
                <span class="we-red">*</span>登录账号
            </label>
            <div class="layui-input-inline">
                <input type="text"  id="code" name="code" th:value="${session.user.code}" required
                       placeholder="登录账号" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="we-red">*</span>将会成为您唯一的登入名
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_pass" class="layui-form-label">
                <span class="we-red">*</span>密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="L_pass" th:value="${session.user.password}" name="password" lay-verify="required"
                       placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                6到16个字符
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
                <span class="we-red">*</span>确认密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="L_repass" th:value="${session.user.password}" required lay-verify="repass"
                       placeholder="请输入确认密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <button style="width: 200px;margin-left: 20%" class="layui-btn" lay-filter="edit" lay-submit>修改</button>
        </div>
    </form>
</div>
<script type="text/javascript">
    layui.use(['form', 'layer', 'jquery', 'admin'], function () {
        var form = layui.form,
            $ = layui.jquery,
            layer = layui.layer;

        //自定义验证规则
        form.verify({
            pass: [/(.+){6,12}$/, '密码必须6到12位']
            , repass: function (value) {
                if ($('#L_pass').val() != $('#L_repass').val()) {
                    return '两次密码不一致';
                }
            }
        });

        //监听提交
        form.on('submit(edit)', function (data) {
            $.post("/user/edit", data.field, function (res) {
                if (res.success) {
                    layer.alert("修改成功", {icon: 6}, function () {
                        refreshParent();
                    });
                } else {
                    layer.msg(res.msg, {icon: 5, time: 1500});
                }
            });
            return false;
        });
    });
</script>
</body>

</html>